//
//  JWTBaseViewController.m
//  JWT
//
//  Created by Apple on 2017/1/1.
//  Copyright © 2017年 com.jwtsoft. All rights reserved.
//

#import "JWTBaseViewController.h"

@interface JWTBaseViewController ()

@end

@implementation JWTBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGB_WhiteBackGround;
    
    [self isHideNavImageViewLine];
}


/**
 找到导航栏下面那条线
 */
-(void) isHideNavImageViewLine{
    UIImageView *navigationImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
    self.navigationImageView = navigationImageView;
}

-(UIImageView *)findHairlineImageViewUnder:(UIView *)view {
    
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}

/**
 初始化导航栏标题
 */
-(void) initWithNavTitle:(NSString *)navTitle{
    //登录的标题栏
    UILabel *naviTitle = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    naviTitle.textColor = RGB_WhiteBackGround;
    naviTitle.text = navTitle;
    naviTitle.textAlignment = NSTextAlignmentCenter;
    naviTitle.font = [UIFont boldSystemFontOfSize:18];
    naviTitle.backgroundColor = [UIColor clearColor];
    self.navigationItem.titleView = naviTitle;
}


/**
 初始化回退箭头
 */
-(void) initWithLeftBarItem{
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 25, 25)];
    [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(navBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = leftBarItem;
    [self.navigationController.navigationBar setTintColor:RGB(46, 46, 46)];
}


/**
 初始化导航栏右键
 */
-(void) initWithRightBarItemWithName:(NSString *)name{
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(5, 5, 50, 30)];
    [rightBtn setTitle:name forState:UIControlStateNormal];
    [rightBtn setTitleColor:RGB_LightGrayBackGround forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:14.0];
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem = rightBarItem;
    self.navigationController.navigationBar.tintColor = RGB(46, 46, 46);
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    self.navigationImageView.hidden = YES;
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [HUD hideUIBlockingIndicator];
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    self.navigationImageView.hidden = YES;
    
}

-(void) navBack{
    [HUD hideUIBlockingIndicator];
     [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
